﻿using KXmlUIControl;
using KWindow.KPageCore;
using LogLib;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace IPCPages
{
    public partial class PageHome : PageControlBase
    {     
        /// <summary>
        /// 连续点击激活次数统计
        /// </summary>
        private int active_click_count = 0;
        private Stopwatch sw = new Stopwatch();
        private PictureBox pictureBox1 = null;
        private Button buttonIPC = null;
        private Button buttonYSL = null;
        private Button buttonIPC_YSL = null;
        private Button buttonYSL_IPC = null;

        public PageHome()
        {
            InitializeComponent();
            SetProcessBase(ProcessHome.Instance);
        }

        private void GetControls()
        {
            pictureBox1 = GetControl<PictureBox>("pictureBox1") as PictureBox;
            buttonIPC = GetControl<Button>("buttonIPC") as Button;
            buttonYSL = GetControl<Button>("buttonYSL") as Button;
            buttonIPC_YSL = GetControl<Button>("buttonIPC_YSL") as Button;
            buttonYSL_IPC = GetControl<Button>("buttonYSL_IPC") as Button;
            SetButtonDefaultStyles(buttonIPC);
            SetButtonDefaultStyles(buttonYSL);
            SetButtonDefaultStyles(buttonIPC_YSL);
            SetButtonDefaultStyles(buttonYSL_IPC);
        }

        //初始化窗体数据
        public override void InitCtrls()
        {
            base.InitCtrls();
            GetControls();          
        }

        //初始化窗体数据
        public override void InitData()
        {
            SD.ClearValue();
            Process.SetValue("ActionIndex", 1);
        }

        /// <summary>
        /// 保存窗体数据(窗体本次做完后, 进入下一步之前)
        /// </summary>
        public override void UpdateData()
        {

        }

        /// <summary>
        /// 清理窗体数据(窗体本次做完后)
        /// </summary>
        public override void ClearData()
        {
            base.ClearData();
        }

        /// <summary>
        /// 窗体关闭时
        /// </summary>
        public override void Close()
        {
            base.Close();
        }

        public override void StartWork()
        {
           base.StartWork();
        }

        public override void StopWork()
        {
            base.StopWork();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (!sw.IsRunning)
            {
                sw.Restart();
                return;
            }
            if (sw.ElapsedMilliseconds > 2000)
            {
                sw.Reset();
                active_click_count = 0;
            }
            else
            {
                active_click_count++;
            }
            if (active_click_count == 2)
            {
                sw.Reset();
                active_click_count = 0;
                Log.WriteAsync("用户打开了管理员选项");
                FormAdministrator form = new FormAdministrator();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    Log.WriteAsync("即将执行管理员选项动作:" + form.SelectAction.ToString());
                    Process.OnTakeAdminAction(form.SelectAction);
                }
            }
        }

        private void ButtonIPC_Click(object sender, EventArgs e)
        {
            MessageBox.Show("ButtonIPC");
        }

        private void ButtonYSL_Click(object sender, EventArgs e)
        {
            Process.ToAnyApp("YSL");
        }

        private void ButtonIPC_YSL_Click(object sender, EventArgs e)
        {
            MessageBox.Show("ButtonIPC_YSL");
        }

        private void ButtonYSL_IPC_Click(object sender, EventArgs e)
        {
            MessageBox.Show("ButtonYSL_IPC");
        }
    }
}
